# 写函数，计算传入函数的字符串中,[数字]、[其他（字母、中文、符号）] 的个数，并返回结果

# def test1(data):
#     numCount = 0
#     for s in data:
#         if s.isdecimal():
#             numCount += 1
#     print(f"数字的个数: {numCount}")
#     print(f"其他的个数: {len(data) - numCount}")
#
#
# test1('123abcd!!@#中')


# 写函数，判断用户传入的对象（字符串、列表、元组）长度是否大于5。

# def test2(data):
#     if len(data) > 5:
#         print("长度大于五")
#     else:
#         print("长度不大五")
#
# test2((1, 2, 3, 4, 5, 6))

# 写函数，函数接收四个参数分别是：姓名，性别，年龄，学历，支持用户持续输入，Q或者q退出，性别默认为男，最后打印出学生的个人信息

# def stuInfo(name, sex, age, ec):
#     print(name, sex, age, ec)
#
# while True:
#     name = input("请输入姓名: ")
#     if name.lower() == 'q':
#         break
#     age = input("请输入年龄: ")
#     if age.lower() == 'q':
#         break
#     sex = input("请输入性别: ")
#     if sex.lower() == 'q':
#         break
#     if not sex:
#         sex = "male"
#     if sex not in ["male", 'female']:
#         sex = "male"
#     ec = input("请输入学历: ")
#     if ec.lower() == 'q':
#         break
#     stuInfo(name, sex, age, ec)

# 写函数，接收n个数字，求这些参数数字的和
# def test4(*arg):
#     sum = 0
#     for a in arg:
#         sum += a
#     print(sum)
#
# test4(1, 2, 3, 4, 5)

# 写函数，函数可以支持接收任意内容（关键字传参）并返回字典。

# def test4(**kw):
#     return kw
#
# print(test4(sex="male"))

# 用递归函数实现斐波那契数列：已知一个数列：1、1、2、3、5、8、13、。。。。的规律为从3开始的每一项都等于其前两项的和，这是斐波那契数列。求满足规律的100以内的所以数据.
# def test5(n):
#     """
#
#     :param n: 指定位数
#     :return:
#     """
#     if n == 1 or n == 2:
#         return 1
#     else:
#         return test5(n - 1) + test5(n - 2)  # n == 3 --> return test5(2) + test5(1)
#
# print(test5(5))


# 用递归函数，来指定查找字典中的key，不论层级多深，只要查找到这个key，就直接print
# 测试数据：
"""
dic = {
    "name": "muzhou",
    "dic1": {
        "name1": "muzhou1",
        "lst1": [
            {
                "name2": "muzhou2",
                "dic2": {
                    "name3": "muzhou3"
                }
            },
            {
                "name4": "muzhou4"
            }
        ]
    }
}
"""
# dic = {
#     "name": "muzhou",
#     "dic1": {
#         "name1": "muzhou1",
#         "lst1": [
#             {
#                 "name2": "muzhou2",
#                 "dic2": {
#                     "name3": "muzhou3"
#                 }
#             },
#             {
#                 "name4": "muzhou4"
#             }
#         ]
#     }
# }

dic = {
    "dic1": {
        "lst1": [
            {
                "name": "muzhou"
            }
        ]
    }
}

def test6(dataMap, findKey):
    if isinstance(dataMap, dict):
        for key, value in dataMap.items():
            if key == findKey:
                print(f"找到你了, 值: {value}")
            else:
                test6(value, findKey)
    elif isinstance(dataMap, list):
        for el in dataMap:
            test6(el, findKey)

test6(dic, findKey="name")